package com.flymobi.service;

import java.util.List;

import com.flymobi.fw.modules.CommonService;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Manager;
import com.flymobi.util.QL;

public class ManagerService extends CommonService {

	public Manager find(String name, String pwd) {
		Manager man = dao.findSingle(Manager.class, QL.HQL.Manager.FIND_BY_NAME,
				new Object[] { name });
		if (man != null) {
			String pass = man.getPwd();
			if (pass != null && pass.equals(pwd)) {
				return man;
			} else {
				return null;
			}
		}
		return man;
	}

	public List<Manager> list() {
		return dao.find(Manager.class, QL.HQL.Manager.LIST, new Object[] {});
	}
	
	public List<Manager> list(String key,int startRow, int pagePerSize) {
		if (StringUtil.isEmpty(key)) {
			key = "";
		}
		return dao.find(Manager.class, QL.HQL.Manager.LIST_KEY, new Object[] {"%" + key + "%"},
				startRow, pagePerSize);
	}
	
	public Long getCount(String key) {
		if (StringUtil.isEmpty(key)) {
			key = "";
		}
		return dao.getCount(QL.HQL.Manager.GET_COUNT_KEY, new Object[] {
					"%" + key + "%"});
	}

	public void save(Manager manager) {
		dao.save(manager);
	}

	public Manager load(String id) {
		return dao.load(Manager.class, new Long(id));
	}
	
	public Manager get(String id) {
		return dao.get(Manager.class, new Long(id));
	}

	public void delete(String id) {
		dao.delete(this.get(id));
	}
}
